layui.use(['form', 'layedit', 'laydate'], function(){
    var form = layui.form
        ,layer = layui.layer
        ,layedit = layui.layedit
        ,laydate = layui.laydate;

    //日期
    laydate.render({
        elem: '#date'
    });
    laydate.render({
        elem: '#date1'
    });

    //创建一个编辑器
    var editIndex = layedit.build('LAY_demo_editor');

    //自定义验证规则
    form.verify({
        title: function(value){
            if(value.length < 3){
                return '标题至少得3个字符啊';
            }
        }
        ,password: [
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
        ]
        ,confirmPassword:function(value){
            if($('input[name=password]').val() !== value)
                return '提示：两次输入密码不一致！';
        }

    });

    //监听指定开关
    form.on('switch(switchTest)', function(data){
        layer.msg('开关checked：'+ (this.checked ? 'true' : 'false'), {
            offset: '6px'
        });
        layer.tips('温馨提示：请注意开关状态的文字可以随意定义，而不仅仅是ON|OFF', data.othis)
    });

    //监听提交
    form.on('submit(demo1)', function(data){
        layer.alert(JSON.stringify(data.field), {
            title: '最终的提交信息'
        })
        return true;
    });

    //表单赋值
    layui.$('#LAY-component-form-setval').on('click', function(){
        form.val('example', {
            "username": "贤心" // "name": "value"
            ,"password": "123456"
            ,"interest": 1
            ,"like[write]": true //复选框选中状态
            ,"close": true //开关状态
            ,"sex": "女"
            ,"desc": "我爱 layui"
        });
    });

    //表单取值
    layui.$('#LAY-component-form-getval').on('click', function(){
        var data = form.val('example');
        alert(JSON.stringify(data));
    });





});



layui.use(['form', 'layer', 'jquery'], function () {
    var form = layui.form,
        layer = parent.layer === undefined ? layui.layer : top.layer
    $ = layui.jquery;

    form.verify({
        pass: [
            /^[\S]{6,12}$/
            ,'密码必须6到12位，且不能出现空格'
        ]

    });


    //验证码
    var checkCode = "";

    $("#sendCheckCode").click(function () {
        var email = $("#email").val();
        if (email == null || email == ""){
            layer.msg("请输入邮箱！！！");
            return;
        }
        var index = layer.open({
            type:3,
            content:"邮件发送中..."
        });
        console.log("asggasg")
        $.ajax({
            url:"/getCheckCode?email="+email,
            type:"get",
            success:function (text) {
                if (text != null && text != ""){
                    layer.close(index);
                    layer.msg("已发送");
                    checkCode = text;
                    countDown();
                } else{
                    layer.alert("获取失败，请重新获取")
                }
            }
        });
    });

    var maxTime = 60;
    function countDown(){
        if (maxTime == 0){
            checkCode = "";
            $("#sendCheckCode").removeClass("layui-btn-disabled");
            $("#sendCheckCode").removeAttr("disabled")
            $("#sendCheckCode").html("获取验证码");
            maxTime = 60;
        }else{
            $("#sendCheckCode").attr("disabled","disabled");
            $("#sendCheckCode").addClass("layui-btn-disabled");
            form.render();
            $("#sendCheckCode").html(maxTime+"秒后重新获取");
            maxTime--;
            setTimeout(countDown,1000);
        }
    }


    //表单输入效果
    $(".loginBody .input-item").click(function (e) {
        e.stopPropagation();
        $(this).addClass("layui-input-focus").find(".layui-input").focus();
    })
    $(".loginBody .layui-form-item .layui-input").focus(function () {
        $(this).parent().addClass("layui-input-focus");
    })
    $(".loginBody .layui-form-item .layui-input").blur(function () {
        $(this).parent().removeClass("layui-input-focus");
        if ($(this).val() != '') {
            $(this).parent().addClass("layui-input-active");
        } else {
            $(this).parent().removeClass("layui-input-active");
        }
    })


})

